package unimelb.distSystems.project2;

/*
 * Lim Ching Lih, 308721
 * Yu Xia, 351025
 * Carlos Vasconcelos, 193554
 */

import java.io.Serializable;
import java.util.Arrays;
import java.util.LinkedList;

import unimelb.distSystems.communications.CORBA.ServiceMatchRoom;
import unimelb.distSystems.communications.CORBA.ServiceMessage;

/*
 * MatchRoom class is an entity type for match room and racing session 
 * Comment on Serializable LinkedList: Standard implementations of List is already serializable
 */
public class MatchRoom implements Serializable {
	private long matchroom_id;
	private String name;
	private LinkedList<String> messages = new LinkedList<String>();
	private int max_players;
	private long host_id;
	//private LinkedList<Long> players=new LinkedList<Long>();
	private long track_id;
	private LinkedList<Long> number_ready_players=new LinkedList<Long>();
	private boolean isInRacingProgress=false;
	
	/*
	 * Constructor
	 */
	public MatchRoom(String name,int max_players,long track_id,long host_id)
	{
		this.matchroom_id=-1;
		this.name=name;
		this.max_players=max_players;
		this.host_id=host_id;
		this.track_id=track_id;
		this.isInRacingProgress=false;
	}
	
	/*
	 * Convert COBRA entity to true java entity
	 */
    public MatchRoom(ServiceMatchRoom room){
        matchroom_id = room.matchroom_id;
        name = room.name;
        max_players = room.max_players;
        this.host_id=-1;
        track_id = room.track_id;
        host_id = room.host_id;
        isInRacingProgress = room.raceInProgress;
    }

    /*
     * Convert true java entity to COBRA entity
     */
    public ServiceMatchRoom getServiceMatchRoom(){
        ServiceMatchRoom room = new ServiceMatchRoom();
        room.matchroom_id = matchroom_id;
        room.name = name;
        room.max_players = max_players;
        room.track_id = track_id;
        room.host_id = host_id;
        room.raceInProgress = isInRacingProgress;

        return room;
    }
	
	/*
	 * Get list of chat messages
	 * Input: Nothing
	 * Output: LinkedList<String> messages
	 */
	public LinkedList<String> getAllMessages()
	{
		return messages;
	}
	
	/*
	 * Get unique ID of match room
	 * Input: Nothing
	 * Output: long value of ID
	 */
	public long getMatchRoomID()
	{
		return matchroom_id;
	}
	
	/*
	 * Get maximum number of players allowed in match room
	 * Input: Nothing
	 * Output: int value of maximum number of players
	 */
	public int getMaxPlayers()
	{
		return max_players;
	}
	
	/*
	 * Get name of the match room, set by host player
	 * Input: Nothing
	 * Output: String name
	 */
	public String getMatchRoomName()
	{
		return name;
	}
	
	/*
	 * Get unique ID of player who hosts this match room
	 * Input: Nothing
	 * Output: long value of player ID
	 */
	public long getHostID()
	{
		return host_id;
	}
	
	/*
	 * Get list of unique IDs of players who are in the match room
	 * Input: Nothing
	 * Output: LinkedList<Long> of IDs
	 */
	/*//INVALIDATED now. Use server interface to get
	public LinkedList<Long> getAllPlayers()
	{
		return players;
	}
	*/
	
	/*
	 * Get the unique of track selected by host player
	 * Input: Nothing
	 * Output: long value of Track ID
	 */
	public long getTrackID()
	{
		return track_id;
	}
	
	/*
	 * Get number of players who are ready for racing
	 * Input: Nothing
	 * Output: int value of number of ready players
	 */
	public int getNumReadyPlayers()
	{
		return number_ready_players.size();
	}
	
	/*
	 * Check of the match room is in currently racing
	 * Input: Nothing
	 * Output: Yes or No on players are playing
	 */
	public boolean isInRacingProgress()
	{
		return isInRacingProgress;
	}
	
	/*
	 * Store player ID of host
	 * Input: Long value of player ID
	 * Output: Nothing
	 */
	public void setHost_id(long host_id) {
        this.host_id = host_id;
    }

	/*
	 * Store unique ID of match room
	 * Input: Long value of match room ID
	 * Output: Nothing
	 */
    public void setMatchroom_id(long matchroom_id) {
        this.matchroom_id = matchroom_id;
    }

    /*
	 * Store maximum number of players allowed
	 * Input: Int value of max players
	 * Output: Nothing
	 */
    public void setMax_players(int max_players) {
        this.max_players = max_players;
    }

    /*
	 * Cache the chat messages
	 * Input: LinkedList messages
	 * Output: Nothing
	 */
    public void setMessages(LinkedList<String> messages) {
        this.messages = messages;
    }

    /*
	 * Store name of match room
	 * Input: String name of match room
	 * Output: Nothing
	 */
    public void setName(String name) {
        this.name = name;
    }

    /*
	 * Store the current number of ready players
	 * Input: Int value of ready players
	 * Output: Nothing
	 */
    public void setNumber_ready_players(LinkedList<Long> number_ready_players) {
        this.number_ready_players = number_ready_players;
    }

    /*
     * //INVALIDATED now. Never used on client side
    public void setPlayers(LinkedList<Long> players) {
        this.players = players;
    }
    */

    /*
	 * Store unique ID of track
	 * Input: Long value of track ID
	 * Output: Nothing
	 */
    public void setTrack_id(long track_id) {
        this.track_id = track_id;
    }
}
